package db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by dllo on 17/4/13.
 */
//管理数据库的工具类
public class BearSQLiteHelper extends SQLiteOpenHelper {
    private static final String NAME_DB = "oil.db";
    private static final int VERSION = 1;
    static final String CARS_TBL = "cars_tbl";
    public static final String RECORDS_TBL = "records_tbl";

    //汽车表中各列的标题名
    static final String _ID = "_id";
    static final String NAME = "name";
    static final String SELECTED = "selected";
    static final String MODEL = "model";
    static final String UUID = "uuid";

    //加油记录表中所有字段的名字
    public static final String RECORD_ID = "_id";
    public static final String DATE = "date";
    public static final String ODOMETER = "odometer";
    public static final String PRICE = "price";
    public static final String TOTAL = "yuan";
    public static final String TYPE = "type";
    public static final String GASSUP = "gassup";
    public static final String REMARK = "remark";
    public static final String CARID = "carId";
    public static final String FORGET = "forget";
    public static final String LIGHTON = "lighton";
    public static final String STATIONID = "stationId";

    //复写构造方法
    BearSQLiteHelper(Context context) {
        super(context, NAME_DB, null, VERSION);
    }

    //复写onCreate方法
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建汽车表
        String sqlCar = "create table " + CARS_TBL + " (" + _ID + " integer primary key autoincrement," + NAME + "  text not null," + SELECTED + " integer not null," + MODEL + " integer," + UUID + " integer);";
        db.execSQL(sqlCar);
        //创建加油记录表
        String sqlRecord = "create table " + RECORDS_TBL + " (" + RECORD_ID + " integer primary key autoincrement," + DATE + " integer not null," + ODOMETER + " integer not null," + PRICE + " float not null," + TOTAL + " float not null," + TYPE + " integer not null," + GASSUP + " integer not null," + REMARK + " text not null," + CARID + " integer not null," + FORGET + " integer not null," + LIGHTON + " integer not null," + STATIONID + " integer not null);";
        db.execSQL(sqlRecord);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
